package com.martin.study;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.ConversionServiceFactoryBean;
import org.springframework.stereotype.Component;

import java.util.Collections;

@Component
public class SpringWithConditionalGenericConverterDemo {
	public static void main(String[] args) {
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringWithConditionalGenericConverterDemo.class);
		UserService userService = context.getBean(UserService.class);
		userService.test();
	}

	@Bean
	public ConversionServiceFactoryBean conversionService() {
		ConversionServiceFactoryBean conversionServiceFactoryBean = new ConversionServiceFactoryBean();
		conversionServiceFactoryBean.setConverters(Collections.singleton(new SpringConverterDemo()));

		return conversionServiceFactoryBean;
	}

	@Component
	public class UserService {

		@Value("孔子墨#男")
		private JdkPropertyEditorDemo.User user;

		public void test() {
			System.out.println(user);
		}

	}
}
